﻿using System;

namespace LinkedInApi
{
    partial class ApiClient
    {
        public static ILogger CreateNoLogger()
        {
            return new DummyLogger();
        }

        public static ILogger CreateConsoleLogger()
        {
            return new Logger();
        }
    }

    public interface ILogger
    {
        void Log(string source, string message, params object[] args);
        void Log(string message);
        void Log(string message, params object[] args);
        void Log(string source, string message);
        void Log(string source, Exception e);
        void Log(Exception e);
    }

    internal class Logger : ILogger
    {
        public void Log(string source, string message, params object[] args)
        {
            Console.WriteLine("[{0:d} {0:HH:mm:ss.fff}]{1}: {2}", DateTime.Now, String.IsNullOrWhiteSpace(source) ? "" : source.Trim().Insert(0, " "), args != null && args.Length > 0 ? String.Format(message, args) : message);
        }     

        public void Log(string message)
        {
            Log(null, message, null);
        }

        public void Log(string message, params object[] args)
        {
            Log(null, message, args);
        }

        public void Log(string source, string message)
        {
            Log(source, message, null);
        }

        public void Log(string source, Exception e)
        {
            Log(source, e.ToString(), null);
        }

        public void Log(Exception e)
        {
            Log(null, e.ToString(), null);
        }
    }

    internal class DummyLogger : ILogger
    {
        public void Log(string source, string message, params object[] args)
        {
        }

        public void Log(string message)
        {
        }

        public void Log(string message, params object[] args)
        {
        }

        public void Log(string source, string message)
        {
        }

        public void Log(string source, Exception e)
        {
        }

        public void Log(Exception e)
        {
        }
    }
}
